package com.jihad.sbd.modules.test.controller;

import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.log;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jihad.sbd.common.utils.ResponseUtil;
import com.jihad.sbd.modules.test.entity.User;
import com.jihad.sbd.modules.test.service.UserService;

@Controller
public class UserController {
	
	private static final Logger log = LoggerFactory.getLogger(UserController.class);

	@Autowired
	private UserService userService;
	@RequestMapping(value="/user/add")
	@ResponseBody
	public ResponseUtil addUser(String username,String password){
		User user = new User();
		user.setUid(3);
		user.setUsername("test");
		user.setPassword("123456");
		userService.addUser(user);
		return ResponseUtil.ok();
	}
	@RequestMapping(value="/user/select")
	@ResponseBody
	public User getUser(Integer id,String username){
		log.info("根据ID或者用户名查找");
		User user = null;
		if(id!=null){
			user = userService.getUserById(id);
		}
		if(username!=null){
			user = userService.getUserByUsername(username);
		}
		return user;
	}
}
